﻿#include "SharedMemoryTest.h"

using namespace SystemTool::Buffer;

int TestSharedMemory()
{
	SharedMemory MyShare;

	MyShare.Configure("MySharedMemory", 1024);

	if (!MyShare.IsOpen())
	{
		MyShare.Open(SM_CREATE_ONLY);
	}

	char buffer[] = "what are you doing?";

	MyShare.Write(buffer, 0, sizeof(buffer));

	MyShare.Close();


	SharedMemory MyShare2;

	MyShare2.Configure("MySharedMemory", 1024);

	if (!MyShare2.IsOpen())
	{
		MyShare2.Open(SM_OPEN_ONLY);
	}

	char buffer2[1024] = { 0 };

	MyShare2.Read(buffer2, 0, sizeof(buffer2));

	MyShare2.Close();

	std::cout << "I get data from the shared memory is:" << buffer2 << std::endl;

	return 0;
}
